'use strict';

angular.module('myApp.classes', ['tm.pagination'])
.controller('classesCtrl',function($scope,$http,$location){
	$scope.selectGrades=[
		{id : '1',name : '一年级'},
		{id : '2',name : '二年级'},
		{id : '3',name : '三年级'},
		{id : '4',name : '四年级'},
		{id : '5',name : '五年级'},
		{id : '6',name : '六年级'}
	];
	$scope.selectGrade = $scope.selectGrades[0].id;
	var content = $scope.selectGrade;

	$scope.update = function(){
		content = $scope.selectGrade;
	}

	// 显示全部班级
	function load(){
		$http.get('v1/classes').success(function(data){
			var data = data.resule.data;
			if (!data.error) {
				$scope.classes = data;
			}else{
				alert(data.message);
			};
		})
	}
	load();
	$scope.load=function(){
		load();
	}

	//搜索
	$scope.search = function(){
		switch(content){
			case '1':content = '一年级';break;
			case '2':content = '二年级';break;
			case '3':content = '三年级';break;
			case '4':content = '四年级';break;
			case '5':content = '五年级';break;
			case '6':content = '六年级';break;
			default :break;
		}
		$http({
			    url: 'v1/classes', 
			    method: "GET",
			    params: {column: 'grade',content:content}
			 }).success(function(data){
	            if(!data.error ){
	            	var temp_result = data.resule.data;
	 				$scope.classes = temp_result;           	
	            }else{
	                alert(data.message);
	            }
	 		});
	}
	//删除班级
	$scope.delete = function(classe){
		
		$http.delete('v1/classes/'+classe.id).success(function(data){
			if (!data.error) {
				alert(data.message);
				load();
			}else{
				alert(data.message);
			};
		})
	}

	//跳转到新建
    $scope.jumpToUrl = function(path) {
        $location.path(path);
        var curUrl = $location.absUrl();
    };

});